<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome to facepoll</title>
        <link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.16.custom.css"/>
        <link rel="stylesheet" type="text/css" href="css/custom.css"/>
        <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
        <script type="text/javascript" src="js/jquery.form.js"></script>
        <script>
            var totalAnswer = 2;
            var maximumAnswer = 5;
            
            $(function() {
                
                var $dialog = $("#pollForm").dialog( {
                    autoOpen: false,
                    closeOnEscape: false,
                    draggable: false,
                    width:500,
                    buttons: [
                        {
                            text: "Submit",
                            click: function() {  
                                $('#createpoll').submit();
                                $(this).dialog("close");
                                return false;           
                            }
                        }
                    ] 
                });
                
                $('#newPoll').click(function() {
                    $dialog.dialog('open');
                    return false;
                });
                
                $('#addAnswer').click(function() {
                    if (totalAnswer+1<=maximumAnswer) {
                        var element = document.createElement("input");
                        element.setAttribute("type", "text");
                        element.setAttribute("id", "txtPollAnswer");

                        var answerSection = document.getElementById("pollOptions");
                        answerSection.appendChild(element);

                        totalAnswer = totalAnswer + 1;
                    }else {
                        
                    }
                });
                
                $("#startDate").datepicker();
                $("#endDate").datepicker();
            });
            
            $(document).ready(function() {                 
                $('#createpoll').ajaxForm();
                
            });            

        </script>
    </head>

    <body>
        <div id="menu">
            <a href="#" id="newPoll">Create New Poll</a>
        </div>
        
        <div id="content">
            
        </div>

        <div id="pollForm" title="Create New Poll">
            <form:form id="createpoll" method="POST" accept-charset="UTF-8" commandName="pollQuestionDTO" action="createPoll.htm">
                <fieldset>
                    <p>
                        <label>Title</label>
                        <form:input path="title" id="txtTitle"></form:input> 
                    </p>
                    <p>
                        <label>Status</label>
                        <form:select path="active" id="selStatus">
                            <option value="true">Active</option>
                            <option value="false">InActive</option>
                        </form:select>

                        <label>Type</label>
                        <form:select path="type" id="type">
                            <option value="0">Private</option>
                            <option value="1">Public</option>
                        </form:select>
                    </p>
                    <p>
                        <label>Start Date</label>
                        <form:input path="startDate" id="startDate"></form:input>
                        <label>End Date</label>
                        <form:input path="endDate" id="endDate"></form:input>
                    </p>
                    <p>
                        <label>Question</label>
                        <form:input path="question" id="txtPollQuestion"></form:input>                        
                    </p>
                    <p>
                        <label>Answers</label>
                        <div id="pollOptions">
                            <form:input path="answer" id="txtPollOption"></form:input>
                            <form:input path="answer" id="txtPollOption"></form:input>
                        </div>
                        <a href="#" id="addAnswer">Add Answer</a>
                    </p>
                </fieldset>
            </form:form>
        </div>
    </body>
</html>
